package com.example.project.mapper;

import com.example.project.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserMapper {

    @Select("select * from t_user")
    List<User> findAll(); //数据查询接口 返回所有数据

    @Update("INSERT INTO t_user(id,username,password) VALUES(#{id},#{username},#{password})")
    @Transactional
    void save(User user); //增加

    @Update("update t_user set username=#{username}, password=#{password} where id=#{id}")
    @Transactional
    void updateById(User user); //修改

    @Delete("delete from t_user where id=#{id}")
    void deleteById(Long id); //根据id删除

    @Select("select * from t_user where id=#{id}")
    User findById(Long id); //根据id进行查找找到一条记录

    @Select("select * from t_user where username=#{username} and password=#{password}")
    User selectByUserNameAndPassword(@Param("username") String username, @Param("password") String password);
}
